package cn.zyjblogs.config.swagger;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
import springfox.documentation.swagger.web.SwaggerResourcesProvider;
import springfox.documentation.swagger.web.UiConfiguration;

/**
 * @author zhuyijun
 */
@RestController
@RequestMapping("/swagger-resources")
public class SwaggerHandler {

    private final SwaggerResourcesProvider swaggerResources;

    private final UiConfiguration uiConfiguration;

    public SwaggerHandler(SwaggerResourcesProvider swaggerResources, UiConfiguration uiConfiguration) {
        this.swaggerResources = swaggerResources;
        this.uiConfiguration = uiConfiguration;
    }

//    @GetMapping("/swagger-resources/configuration/security")
//    public Mono<ResponseEntity<SecurityConfiguration>> securityConfiguration() {
//        return Mono.just(new ResponseEntity<>(
//                Optional.ofNullable(OAuth2ResourceServerAutoConfiguration).orElse(SecurityConfigurationBuilder.builder().build()), HttpStatus.OK));
//    }

    @GetMapping("")
    public Mono<ResponseEntity> swaggerResources() {
        return Mono.just((new ResponseEntity<>(swaggerResources.get(), HttpStatus.OK)));
    }

    @GetMapping("/configuration/ui")
    public Mono<ResponseEntity<UiConfiguration>> uiConfiguration() {
        return Mono.just(new ResponseEntity<>(uiConfiguration, HttpStatus.OK));
    }

}
